package com.hzlx.dao.impl;

import com.hzlx.dao.BaseDao;
import com.hzlx.dao.TUserInfoDao;
import com.hzlx.entity.TUserInfo;

import java.util.Date;
import java.util.List;

/**
 * @author 86166
 * @version 1.0
 * @description: TODO
 * @date 2023/4/9 22:36
 */
public class TUserInfoDaoImpl extends BaseDao<TUserInfo> implements TUserInfoDao {
    @Override
    public int deleteByPrimaryKey(Integer id) {
        String sql = "delete * from t_user_info where id=?";
        return executeUpdate(sql, id);
    }

    @Override
    public int insert(TUserInfo record) {
        String sql = "insert into t_user_info values(?,?,?,?,?,default,now())";
        return executeUpdate(sql, null, record.getNickName(), record.getUserName(), record.getPassword(), record.getTel());
    }

    @Override
    public int insertSelective(TUserInfo record) {
        return 0;
    }

    @Override
    public TUserInfo selectByPrimaryKey(Integer id) {
        String sql = "select * from t_user_info where id = ?";
        List<TUserInfo> tUserInfos = executeQuery(sql, TUserInfo.class, id);
        TUserInfo tUserInfo = null;
        if (tUserInfos.size()>0) {
            for (TUserInfo userInfo : tUserInfos) {
                tUserInfo = userInfo;
            }
        }
        return tUserInfo;
    }

    @Override
    public int updateByPrimaryKeySelective(TUserInfo record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(TUserInfo record) {
        String sql = "update t_user_info set nick_name=?,user_name=?, password=?,tel=?,status=?,create_time=? where id=?";
        return executeUpdate(sql, record.getNickName(), record.getUserName(), record.getPassword(), record.getTel(), record.getStatus(), record.getCreateTime());
    }

    @Override
    public List<TUserInfo> selectUserByUserNameAndPassword(String userName, String password) {
        String sql = "select * from t_user_info where user_name =? and password=?";
        List<TUserInfo> tUserInfos = executeQuery(sql, TUserInfo.class,userName, password);
        return tUserInfos;
    }
}
